package com.chance.cc.crawler.development.bootstrap.sohu.article;

import com.alibaba.fastjson.JSON;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRecord;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName song
 * @Description TODO
 * @Author ding
 * @Date 2021/9/2 14:00
 * @Version 1.0
 * 搜狐 车系文章采集
 **/
public class SoHuArticleStart {
    private static final String domain = "sohu";
    private static Proxy proxy = new Proxy();
    static {
        //代理配置
        //HL89Q19E86E2987D
        //71F33D94CE5F7BF2
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }

    public static void main(String[] args) {
        article();
    }

    private static void article(){
        String site = "article";
        String siteBiz  = "article_realtime";
        String url = "http://db.auto.sohu.com/jike01/6463";
        ///http://db.auto.sohu.com/jike01/6463
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*100,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        record.tagsCreator().bizTags().addSiteBiz(siteBiz);

        CrawlerRecord filterRecord = new CrawlerRecord();
        filterRecord.setFilter(CrawlerEnum.CrawlerRecordFilter.dateRange);
        filterRecord.addFilterInfo(FilterUtils.dateRangeFilterInfo(24*100,null));
        record.tagsCreator().bizTags().addCustomKV("comment_record_filter_info", JSON.toJSONString(filterRecord));


        CrawlerRequestRecord keyRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPageItem)
                .httpUrl("http://192.168.1.215:9599/v1/meta/sohu/keys?site=article")  //todo 关键字传入
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.supportSource)
                .requestLabelTag(CrawlerEnum.CrawlerRequestType.internalDownload)
                .build();


        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","F:\\chance_log\\sohu\\article\\data.log",false)
                .fileResultPipeline("redis","F:\\chance_log\\sohu\\article\\Url.log",false)
                .requestRecord(record)
                //.supportRecord(keyRecord)
                .build("com.chance.cc.crawler.development.scripts.sohu")
                .start();
    }
    @Test
    public void s (){
        String s = "&#xD;\n" +
                "                            &#xD;\n" +
                "                                1来源：孤风笑对孤&#xD;\n" +
                "                            (2021-9-1)&#xD;";
        Matcher mt = Pattern.compile("\\(.*\\)").matcher(s);
        String a = null;
        while (mt.find()){
            a = mt.group();
            System.out.println(mt.group(0));
            //System.out.println(mt.group(1));
            //System.out.println(mt.group(2));
        }
        a = a.substring(1,a.length()-1);
        String[] split = a.split("-");
        if (split[1].length() != 2){
            split[1] = "0"+split[1];
        }
        if (split[2].length() != 2){
            split[2] = "0"+split[2];
        }
        String time = split[0]+"/"+split[1]+"/"+split[2];
        System.out.println(time);
    }

}
